package weekMatch.two_107;

public class LeeCode_02 {
    public static void main(String[] args) {
        System.out.println(longestString(2, 5, 1));
        System.out.println(longestString(50, 50, 50));
        System.out.println(longestString(1, 39, 14));
    }
    private static int longestString(int x, int y, int z) {
        int[] ans = new int[1];
        dfs(x - 1, y, z, 1, 1, ans);
        dfs(x, y - 1, z, 2, 1, ans);
        dfs(x, y, z - 1, 3, 1, ans);
        return ans[0];
    }
    private static void dfs(int x, int y, int z, int type, int count, int[] ans){
        if (x == -1 || y == -1 || z == -1){
            ans[0] = Math.max(ans[0], (count - 1 + (Math.max(z, 0))) * 2);
            return;
        }
        if (type == 1){
            dfs(x, y - 1, z, 2, count + 1, ans);
        }else if (type == 2){
            if (z > 0){
                dfs(x, y, z - 1, 3, count + 1, ans);
            }else {
                dfs(x - 1, y, z, 1, count + 1, ans);
            }
        }else {
            dfs(x - 1, y, z, 1, count + 1, ans);
        }
    }
}